package com.googlecode.ivybeans.module.util;

import com.googlecode.ivybeans.module.IvyLibraryController;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.logging.Logger;

public class ILCListener implements PropertyChangeListener{

    private static final Logger LOG = Logger.getLogger("com.googlecode.ivybeans.module.util.ILCListener");


    public void propertyChange(PropertyChangeEvent evt) {
        if (IvyLibraryController.CONFIGURATION_CHANGE.equals(evt.getPropertyName())
                || IvyLibraryController.DESCRIPTOR_CHANGE.equals(evt.getPropertyName())
                || IvyLibraryController.DESCRIPTOR_CONTENT_CHANGE.equals(evt.getPropertyName())
                || IvyLibraryController.IVY_ENABLE_STATE_CHANGE.equals(evt.getPropertyName())
                || IvyLibraryController.IVY_LIBRARY_RESOLVED.equals(evt.getPropertyName())
                || IvyLibraryController.SETTINGS_CHANGE.equals(evt.getPropertyName())
                || IvyLibraryController.SETTINGS_CONTENT_CHANGE.equals(evt.getPropertyName())
                ) {
            log(evt);
        }
    }

//    private void onDescriptorChange(PropertyChangeEvent event) {
//    }

    private void log(PropertyChangeEvent evt) {
        LOG.fine(String.format("%s (%s -> %s)", evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()));
    }
}

